home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubmalm.zip / pell.ub < prev    next >
Text File  |  1990-08-22  |  696b  |  19 lines

  1.    10   *Pell(D,&X,&Y,&F)
  2.    20   ' Solves X^2 - D Y^2 = F.  F is 1 or -1, not your choice, but
  3.    30   ' returned by the subroutine. F = 0 for error.
  4.    40   ' 23 April 1990.  Modeled on the Pascal version.
  5.    50   local Leng%=0,H1=0,H2=1,K1=1,K2=0,Sqd,A,Te,U,V,Uu,Vv
  6.    60   if D<1 then F=0:return endif
  7.    70   Sqd=isqrt(D):if res=0 then F=0 return endif
  8.    90   A=Sqd:U=D-A*A:Uu=U:V=A:Vv=V
  9.   120   repeat
  10.   130   Te=H1+H2*A:H1=H2:H2=Te
  11.   140   Te=K1+K2*A:K1=K2:K2=Te
  12.   150   inc Leng%
  13.   160   A=(Sqd+V)\U:Te=res
  14.   170   V=U*A-V:U=(D-V*V)\U
  15.   180   until and{V=Vv,U=Uu}
  16.   190   X=H2:Y=K2
  17.   200   if odd(Leng%) then F=-1 else F=1 endif
  18.   210   return ' End of subroutine Pell
  19.